home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 July / EnigmA AMIGA RUN 20 (1997)(G.R. Edizioni)(IT)[!][issue 1997-07 & 08][EAR-CD IV].iso / earcd / dev / c / amcsrc2.lha / AMCSources2 / NeuralN / CPARSER.cc < prev    next >
C/C++ Source or Header  |  1992-11-18  |  2KB  |  127 lines

  1. /*
  2. *-----------------------------------------------------------------------------
  3. *    file:    cparser.c
  4. *    desc:    simple command parser
  5. *    by:    patrick ko
  6. *    date:    22 aug 91
  7. *    revi:    26 feb 92 ; response file feature
  8. *-----------------------------------------------------------------------------
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12.  
  13. #ifdef __TURBOC__
  14. #include <mem.h>
  15. #include <ctype.h>
  16. #endif
  17.  
  18. #include "cparser.h"
  19.  
  20. CMDTBL    cmdtbl[] =
  21.     {
  22.     {CMD_DIMINPUT,        "-i="},
  23.     {CMD_DIMOUTPUT,        "-o="},
  24.     {CMD_DIMHIDDENY,    "-hh="},
  25.     {CMD_DIMHIDDEN,        "-h="},
  26.     {CMD_TRAINFILE,        "-ftrain="},
  27.     {CMD_TOTALPATT,        "-samp="},
  28.     {CMD_DUMPIN,        "-fdumpin="},
  29.     {CMD_DUMPFILE,        "-fdump="},
  30.     {CMD_RECOGFILE,        "-frecog="},
  31.     {CMD_OUTFILE,        "-fout="},
  32.     {CMD_TRAINERR,        "-err="},
  33.     {CMD_TOLER,        "-torerr="},
  34.     {CMD_REPORT,        "-r="},
  35.     {CMD_TDUMP,        "-tdump="},
  36.     {CMD_TIMER,        "-t"},
  37.     {CMD_WPOS,        "-w+="},
  38.     {CMD_WNEG,        "-w-="},
  39.     {CMD_COMMENT,        "//"}
  40.     };
  41.  
  42. static int    cmdtblsize = 0;
  43. static int    cmdargc = 0;
  44. static int    cmdcnt = 0;
  45. static char    **cmdargv;
  46. static FILE     *frsp = NULL;
  47. int cmdsearch( str, rest )
  48. char    *str;
  49. char    *rest;
  50. {
  51.     int    i, l;
  52.     
  53.     for (i=0; i<cmdtblsize; i++)
  54.         {
  55.         l = strlen( cmdtbl[i].cmdstr );
  56.         if (!memcmp(str, cmdtbl[i].cmdstr, l))
  57.             {
  58.             strcpy( rest, str + l );
  59.             return (cmdtbl[i].cmdno);
  60.             }
  61.         }
  62.     strcpy( rest, str );
  63.     return (CMD_NULL);
  64. }
  65.  
  66. int cmdinit( argc, argv )
  67. int    argc;
  68. char    **argv;
  69. {
  70.     cmdtblsize = sizeof(cmdtbl) / sizeof(cmdtbl[0]);
  71.     cmdargc = argc;
  72.     cmdargv = argv;
  73. }
  74.  
  75. int cmdget( rest )
  76. char     *rest;
  77. {
  78.     int    i, j;
  79.     char    nstr[129];
  80.     char    *rspname;
  81.  
  82.     if ((cmdcnt >= cmdargc - 1) && (frsp == NULL))
  83.         {
  84.         return (-1);
  85.         }
  86.     else
  87.         {
  88.         /* test for response file */
  89.         if (frsp == NULL)
  90.             {
  91.             rspname = *(cmdargv + cmdcnt + 1);
  92.             if (*rspname == '@')
  93.                 {
  94.                 rspname++;
  95.                 cmdcnt++;
  96.                 if ((frsp = fopen(rspname, "r")) == NULL)
  97.                 {
  98.                 fprintf(stderr, "rsp file open fails\n");
  99.                 exit (1);
  100.                 }
  101.                 }
  102.             }
  103.         if (frsp != NULL)
  104.             {
  105.             *nstr = 0;
  106.             for (;!strlen(nstr)&&!feof(frsp);)
  107.                 {
  108.                 fgets(nstr, 128, frsp);
  109.                 for (i=j=0; i<strlen(nstr); i++)
  110.                     {
  111.                     if (!isspace(nstr[i]))
  112.                         {
  113.                         nstr[j++] = nstr[i];
  114.                         }
  115.                     }
  116.                 nstr[j] = 0;
  117.                 }
  118.             if (strlen(nstr))
  119.                 return (cmdsearch( nstr, rest ));
  120.             fclose(frsp);
  121.              frsp = NULL;
  122.             if (cmdcnt >= cmdargc - 1) return (-1);
  123.             }    
  124.         return (cmdsearch( *(cmdargv + ++cmdcnt), rest ));
  125.         }
  126. }
  127.